package com.nuttysoft.fangchan.scrolllistview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        final LinearLayout lin = (LinearLayout) this.findViewById(R.id.lin);
        final Animation animationup = AnimationUtils.loadAnimation(this, R.anim.up);
        final Animation animationdown = AnimationUtils.loadAnimation(this, R.anim.down);
        MyListView listview = (MyListView) this.findViewById(R.id.listview);
        listview.setAdapter(new BaseAdapter() {
            @Override
            public int getCount() {
                return 30;
            }

            @Override
            public Object getItem(int position) {
                return new Object();
            }

            @Override
            public long getItemId(int position) {
                return position;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View inflate = getLayoutInflater().inflate(R.layout.ss, null);
                TextView tv = (TextView) inflate.findViewById(R.id.tv);
                tv.setText(position + "");
                return inflate;
            }
        });

        listview.setOnScrollListener(new MyListView.OnScrollListener() {
            @Override
            public void up() {
                lin.clearAnimation();
                lin.startAnimation(animationup);
            }

            @Override
            public void down() {
                lin.clearAnimation();
                lin.startAnimation(animationdown);
            }
        });
    }
}
